/* GUI CONVERTED from ecqmcpy.p (converter v1.76) Thu May  8 00:26:24 2003 */
/* ecqmcpy.p - Item Specification Copy from Quality Module               */
/* Copyright 1986-2003 QAD Inc., Carpinteria, CA, USA.                   */
/* All rights reserved worldwide.  This is an unpublished work.          */
/* $Revision: 1.5.1.6 $                                                         */
/*V8:ConvertMode=Maintenance                                             */
/* Revision: 8.6    Last Modified: 12/05/96     BY: Joe Gawel       *K00C*/
/* Revision: 8.6    Last Modified: 06/18/97     BY: Joe Gawel       *K0FB*/

/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane     */
/* REVISION: 9.1      LAST MODIFIED: 08/14/00 BY: *N0KW* Jacolyn Neder        */
/* $Revision: 1.5.1.6 $      BY: Karan Motwani         DATE: 05/01/03  ECO: *N2DZ*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/*K00C* - Copy from Quality Module (ipd_det) to PCC Module (ecd4_det)    */

/* SHARED VARIABLE DEFINITIONS */
{mfdeclre.i}

/* EXTERNAL LABEL INCLUDE */
{gplabel.i}

/* PASSED PARAMETERS */
{ecmtparm.i}

define variable routing like ecd4_routing        no-undo.
define variable op      like ipd_op format ">>>" no-undo.
define variable part    like ipd_part            no-undo.
define variable section as   integer             no-undo.
define variable i       as   integer             no-undo.
define variable yn      as   logical             no-undo.

define buffer cmtdet for cmt_det.

define new shared temp-table ipdtable
   field ipdstar     as   character format  "x(1)"
   field ipdrouting  like ipd_routing
   field ipdpart     like ipd_part
   field ipdop       like ipd_op
   field ipdnbr      like ipd_nbr
   field ipdtest     like ipd_test label "Number"
   field ipdlabel    like ipd_label
   field ipdtol      like ipd_tol
   field ipdtoltype  like ipd_tol_type
   field ipdrecid    as   recid.

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
part    colon 19 pt_desc1 format "x(39)" no-label
   routing colon 19 label "Routing/Procedure"
   ro_desc  format "x(39)" no-label
 SKIP(.4)  /*GUI*/
with frame qm1 width 80 side-labels NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-qm1-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame qm1 = F-qm1-title.
 RECT-FRAME-LABEL:HIDDEN in frame qm1 = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame qm1 =
  FRAME qm1:HEIGHT-PIXELS - RECT-FRAME:Y in frame qm1 - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME qm1 = FRAME qm1:WIDTH-CHARS - .5.  /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame qm1:handle).

for first ecm_mstr
   fields (ecm_mstr ecm_nbr)
   where recid(ecm_mstr) = ecm_recid
no-lock:
end. /* FOR FIRST ecm_mstr ... */

mainloop:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

   /* CLEAN UP FROM PREVIOUS ITERATIONS */
   for each ipdtable
   exclusive-lock:
      delete ipdtable.
   end. /* FOR EACH IPDTABLE... */

   update
      part
      routing
   with frame qm1
   editing:
      if frame-field = "part"
      then do:
         {mfnp05.i  ipd_det ipd_itemtype "((ipd_start = ? or
              ipd_start <= today) and (ipd_end = ? or today <= ipd_end))"
            ipd_part "input part"}

         if recno <> ?
         then do:
            display  ipd_part @ part
                     ipd_routing @ routing
            with frame qm1.
            for first pt_mstr
               fields(pt_desc1 pt_part)
               where pt_part = input part
            no-lock:
               display pt_desc1 with frame qm1.
            end. /* FOR FIRST pt_mstr ... */
         end. /* IF recno <> ? */
      end. /* IF frame-field = "part" */

      else
         if frame-field = "routing"
         then do:
            {mfnp05.i ipd_det ipd_itemtype
             "ipd_part = input part and ((ipd_start = ? or
              ipd_start <= today) and (ipd_end = ? or today <= ipd_end))"
              ipd_routing "input routing"}

            if recno <> ?
            then do:
               display ipd_part @ part
                       ipd_routing @ routing
               with frame qm1.

               for first pt_mstr
                  fields(pt_desc1 pt_part)
                  where pt_part = input part
               no-lock:
                  display pt_desc1 with frame qm1.
               end. /* FOR FIRST pt_mstr ... */

               for first ro_det
                  fields(ro_desc ro_routing)
                  where ro_routing = input routing
               no-lock:
                  display ro_desc with frame qm1.
               end. /* FOR FIRST ro_det */
            end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* IF recno <> ? */
         end. /* IF frame-field = "routing" */
         else do:
            readkey.
            apply lastkey.
            status input.
         end. /* ELSE DO */
   end. /* EDITING */

   for first pt_mstr
      fields(pt_desc1 pt_part)
      where pt_part = input part
   no-lock:
   end. /* FOR FIRST pt_mstr */

   if not available pt_mstr
   then do:
      /* ITEM NUMBER DOES NOT EXIST */
      {pxmsg.i &MSGNUM=16 &ERRORLEVEL=3}
      next-prompt part.
      undo, retry.
   end. /* IF NOT AVAILABLE pt_mstr */

   display pt_desc1 with frame qm1.

   for first ro_det
      fields(ro_desc ro_routing)
      where ro_routing = input routing
   no-lock:
   end. /* FOR FIRST ro_det... */

   if not available ro_det
   then do:
      /* ROUTING DOES NOT EXIST */
      {pxmsg.i &MSGNUM=126 &ERRORLEVEL=3}
      next-prompt routing.
      undo, retry.
   end. /* IF NOT AVAILABLE ro_det */

   display ro_desc with frame qm1.

   for first ipd_det
      where ipd_routing = routing and
            ipd_part    = part
   no-lock:
   end. /* FOR FIRST ipd_det */

   if not available ipd_det
   then do:
      /* NO RECORD AVAIL BASED ON SELECTION */
      {pxmsg.i &MSGNUM=5657 &ERRORLEVEL=3}
      next-prompt part.
      undo, retry.
   end. /* IF NOT AVAILABLE ipd_det */

   /* CREATE TEMP TABLE RECORDS */
   for each ipd_det
      where ipd_routing = routing and
            ipd_part    = part and
            ((ipd_start <= today or ipd_start = ?) and
            (ipd_end >= today or ipd_end = ?))
   no-lock:
      create ipdtable.
      assign
         ipdrouting = ipd_routing
         ipdpart    = ipd_part
         ipdop      = ipd_op
         ipdnbr     = ipd_nbr
         ipdtest    = ipd_test
         ipdlabel   = ipd_label
         ipdtol     = ipd_tol
         ipdtoltype = ipd_tol_type
         ipdrecid   = recid(ipd_det).

      if recid(ipdtable) = -1
      then .

   end. /* FOR EACH ipd_det ... */

   clear frame w all.

   {gprun.i ""ecqmcpy1.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


   if keyfunction(lastkey) = "GO" or
                   lastkey = keycode("RETURN")
   then do:
      /* FOR EACH RECORD SELECTED */
      for each ipdtable
         where ipdstar = "*":
/*GUI*/ if global-beam-me-up then undo, leave.

         for first ipd_det
            where recid(ipd_det) = ipdrecid
         no-lock:
            if can-find(first ecd4_det where ecd4_part = ipd_part and
               ecd4_routing = ipd_routing and
               ecd4_op = ipd_op and
               ecd4_sequence = ipd_test and
               ecd4_nbr = ecm_nbr)
            then do:
               yn = no.
               /*TARGET EXISTS. CONTINUE?*/
               {pxmsg.i &MSGNUM=5632 &ERRORLEVEL=2 &CONFIRM-TYPE=yn}

               if not yn
               then
                  undo mainloop, retry mainloop.
                  leave.
            end. /* IF CAN-FIND(FIRST ecd4_det... */
         end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* FOR FIRST ipd_det... */
      end. /* FOR EACH ipdtable... */

      for each ipdtable
         where ipdstar = "*":
/*GUI*/ if global-beam-me-up then undo, leave.

         for first ipd_det
            where recid(ipd_det) = ipdrecid
         no-lock:
            find first ecd4_det
               where ecd4_part     = ipd_part and
                     ecd4_routing  = ipd_routing and
                     ecd4_op       = ipd_op and
                     ecd4_sequence = ipd_test and
                     ecd4_nbr      = ecm_nbr
            exclusive-lock no-error.
            if not available ecd4_det
            then do:
               create ecd4_det.
               assign
                  ecd4_seq = ipd_test
                  ecd4_part = ipd_part
                  ecd4_routing = ipd_routing
                  ecd4_op = ipd_op
                  ecd4__qadc01 = "no"
                  ecd4_property = ipd_label
                  ecd4_propertyum = ipd_tol_type
                  ecd4_spec_det = ipd_tol
                  ecd4_testmthd = ipd_testmthd
                  ecd4_attribute = ipd_attribute.

               if recid(ecd4_det) = -1
               then .

               if available ecm_mstr
               then
                  ecd4_nbr = ecm_nbr.

               if ipd_cmtindx <> 0
               then do:
                  {gpcmtcpy.i &old_index = ipd_cmtindx
                     &new_index = ecd4_cmtindx
                     &counter   = i
                     }
               end. /* IF ipd_cmtindx <> 0 */
            end.    /* IF NOT AVAILABLE ecd4_det */
         end.
/*GUI*/ if global-beam-me-up then undo, leave.
      /* FOR FIRST ipd_det... */
      end.        /* FOR EACH ipdtable    */

      for each ipdtable
      exclusive-lock:
         delete ipdtable.
      end. /* FOR EACH ipdtable ... */
      do:
         /*PROCESS COMPLETE*/
         {pxmsg.i &MSGNUM=1107 &ERRORLEVEL=1}
         pause.
      end.    /* DO */

   end.      /* IF KEYFUNCTION(LASTKEY) = "GO" */
   else
      apply lastkey.

end. /* MAINLOOP: REPEAT: */
